<?php

class DBO extends Singleton implements iSingleton {

    public $db;
    protected $dsn;
    protected $options;

    public $log_trace = array();

    public $queries_count = 0;

    protected function __construct() {

        $this->dsn = ''; // INSERT YOUR DSN HERE
        $this->options = array(
            'debug' => 2,
            'portability' => DB_PORTABILITY_ALL,
        );

        $this->db =& DB::connect($this->dsn, $this->options);

        throwOnError($this->db);
    }

    public static function getInstance() {
            return parent::getInstance(__CLASS__);
    }

    public function __call( $name, $arguments ) {
        $result = call_user_func_array(array($this->db, $name), $arguments);

        $this->log_trace[] = $this->db->last_query;

        if(in_array($name, array('query', 'getOne', 'getAll', 'getRow', 'nextId', 'execute')))
            $this->queries_count++;

        return $result;
    }

}